package com.java.collectionSort;

import java.util.Iterator;

/**
 * 班级
 */
public class MyClass implements Iterator<String>, Iterable<String>{
    private String[] stuNames = {
        "张三", "李四", "王五", "赵六", "孙七", "周八",
            "吴九", "郑十", "冯十一", "陈十二", "楚十三",
            "魏十四", "吕十五", "施十六", "张十七", "李十八",
            "王十九", "赵二十", "孙二十一", "周二十二", "吴二十三"
    };

    //当前下标
    private int index = -1;

    @Override
    public boolean hasNext() {
        //如果下标没有到最后一位
        return index < stuNames.length - 1;
    }

    @Override
    public String next() {
        //向后移动下标
        index++;
        //返回当前数据
        return stuNames[index];
    }

    @Override
    public Iterator<String> iterator() {
        return this;
    }

    public static void main(String[] args){
        MyClass myClass = new MyClass();
        /*while (myClass.hasNext()){
            System.out.println(myClass.next());
        }*/
        for (String str : myClass){
            System.out.println(str);
        }
    }
}
